/**
 * 
 * @Author : woon
 * @Timestamp : 2016-08-04
 */
var nf = sm("do_Notification");
var page = sm("do_Page");
var dialog = sm("do_Dialog");
var openHelper = require("helper/open");
var circleUrl = require("url/circle");
var http = require("helper/http");
var userUtil = require("helper/user");
var root = ui("$");
var btnSet = ui("btnSet");

root.setMapping({
	"do_ALayout_root.tag" : "id",//圈子id
	"btnUpgrade.tag" : "type",
	"btnSet.tag" : "auditStatus",
	"btnDismiss.tag":"zoneLevel" //当前区域范围
});
root.on("dataRefreshed", function(){
	var auditStatus = ui("btnSet").tag;//审核状态
	if(auditStatus!=2){//未审核或不通过
		ui("btnUpgrade").visible = false;
	}
	var zoneLevel = ui("btnDismiss").tag;//当前区域范围
	if(zoneLevel >= 4){//已经是全国范围,不能再升级
		ui("btnUpgrade").visible = false;
	}
});

//管理圈子
ui("btnSet").on("touch",function(){
	var circleId = ui("do_ALayout_root").tag;
	openHelper.open("source://view/circle/base/manageOne/main.ui",{circleId:circleId});
})

//管理话题
ui("btnTopic").on("touch",function(){
	var circleId = ui("do_ALayout_root").tag;
	openHelper.open("source://view/circle/topic/manage/topic4circle.ui",{circleId:circleId});
})


//解散圈子
ui("btnDismiss").on("touch", function(data, e) {
	if(userUtil.loginToken()===""){
		nf.alert("您还没有登录哦.");
	}else{
		nf.confirm("圈子解散后不能恢复哦。确定要继续吗?", "", "确定", "取消", function(data, e) {
			if (data == 1) {
				var circleId = ui("do_ALayout_root").tag;
				http.post(circleUrl.url.base.dismiss,{"id":circleId},function(data){
					nf.toast("解散成功");
					page.fire("dismiss_circle", circleId);
				});
			}
		})
		
	}
})

//升级圈子
ui("btnUpgrade").on("touch", function(data, e) {
	//nf.toast("该功能还未开放!");
	//return;
	if(userUtil.loginToken()===""){
		nf.alert("您还没有登录哦.");
	}else{
		var circleId = ui("do_ALayout_root").tag;
		openHelper.open("source://view/circle/base/upgrade/apply.ui",{circleId:circleId});
	}
})